﻿
@{
    ViewBag.Title = "设备管理";
}

<div class="row col-md-12 ml-0" style="height:5vh;display:table-cell;vertical-align:middle">
    <strong class="font-rfs" style="margin-right: 1rem;">设备管理</strong>
</div>
<div class="row col-md-12 ml-0 pre-scrollable" style="min-height:90vh;">
    <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-3" style="min-height:90vh;">
        <div class="row col-md-12 tab-content" style="padding-left: 0;padding-right: 0px;right: -15px;height: 3vh;">
            <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
                <li id="li-tabEqList" class="tabButton col-md-3 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                    <a id="a-tabEqList" href="#tabEqList" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">设备列表</a>
                </li>
                <li class="col-md-9 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
            </ul>
        </div>
        <div class="row col-md-12 tab-content tab-body" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;min-height: 87vh;">
            <div class="col-md-12 ml-0 mr-0 tab-pane active" id="tabAnalyte" style="padding-left: 0px;padding-right: 0px;">
                <div class="row col-md-12" style="padding-right: 0px;">
                    <button id="EqManager-AddEq" class="btn btn-rfs"><i class="bi-plus-square" style="color:#007bff"></i> 添加</button>
                    <button id="EqManager-RemoveEq" class="btn btn-rfs"><i class="bi-trash" style="color:red"></i> 删除</button>
                    <button id="EqManager-EnableEq" class="btn btn-rfs"><i class="bi-sign-stop-fill" style="color:forestgreen"></i> 启用/停用</button>
                    <button id="EqManager-ScrapEq" class="btn btn-rfs"><i class="bi-stop-circle" style="color:red"></i> 报废</button>
                    <select id="EqManager-SelectType" class="form-control font-rfs border-radius-noradius custom-headtoolbar-select" style="margin-left: 5px;width:100% !important;"></select>
                </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12">
                    <table id="EqManager-tabEq" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>设备编号</th>
                                <th>设备名称</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row rounded col-md-9 ml-1" style="min-height:90vh;">
        <div class="row col-md-12 tab-content" style="padding-left: 0;padding-right: 0px;right: -15px;height: 3vh;">
            <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
                <li id="li-tabEqBaseInfo" class="tab tabButton col-md-1 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                    <a id="a-tabEqInfo" href="#tabEqInfo" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">基本信息</a>
                </li>
                <li id="li-tabMaintain" class="tab tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabMaintain" href="#tabMaintain" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">维护管理</a>
                </li>
                <li id="li-tabRole" class="tab tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabRole" href="#tabRole" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">备件管理</a>
                </li>
                <li id="li-tabUseRecord" class="tab tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabUseRecord" href="#tabUseRecord" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">使用记录</a>
                </li>
                <li class="col-md-8 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
            </ul>
        </div>
        <div class="row col-md-12 tab-content tab-body" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;min-height: 87vh;">
            <div class="col-md-12 ml-0 mr-0 tab-pane active" id="tabEqInfo" style="padding-left: 0px;padding-right: 0px;">@*基本信息*@
                <div class="row col-md-12" style="min-height:5vh;">
                    <button id="EqManager-SaveEqInfo" class="btn btn-rfs"><i class="bi-database-fill-up" style="color:#007bff"></i> 保存</button>
                    <button id="EqManager-ManagerFiles" class="btn btn-rfs"><i class="bi-file-earmark-arrow-up-fill" style="color:#007bff"></i> 附件</button>
                </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12" style="height:80vh;overflow-x:auto">
                    <table class="table table-sm">@*设备基本信息*@
                        <tbody>
                            <tr style="height:1vh;">
                                <td style="width:1%;border-top:0;"></td>
                                <td style="width:3%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:8%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:5%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:13%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:7%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:1%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:6%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:8%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:11%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:1%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:7%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:13%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:13%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:3%;background-color:#5d6b98;border-top:0"></td>
                                <td style="width:1%;border-top:0"></td>
                            </tr>
                            <tr style="height:1vh;">
                                <td style="border-top:0" colspan=6></td>
                                <td style="background:url(/StaticFile/head_left.png) no-repeat;background-size:cover;border-top:1px"></td>
                                <td style="background-color:#5d6b98;border-top:0" colspan=3></td>
                                <td style="background:url(/StaticFile/head_right.png) no-repeat;background-size:cover;border-top:1px"></td>
                                <td style="border-top:0" colspan=5></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0" colspan=2></td>
                                <td style="border-top:0;padding-bottom:0;" colspan=4>
                                    <input id="EqId" class="font-rfs" readonly="readonly" disabled="disabled" style="color:#5d6b98;font-size:calc(0.7em + 0.6vw);font-weight: bold;border:none" placeholder="设备编号"/>
                                </td>
                                <td style="border-top:0" colspan=10></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0" colspan=2></td>
                                <td style="border-top:0;padding-top:0;" colspan=4>
                                    <input id="EqName" class="font-rfs" style="color:#5d6b98;font-size:calc(0.4em + 0.6vw);font-weight: bold;border:none" placeholder="设备名称"/>
                                </td>
                                <td style="border-top:0" colspan=10></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0;" colspan=2></td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 类型：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <select id="Type" class="form-control font-rfs border-radius-noradius custom-td-select" style="color:#5d6b98;width:100% !important;"></select>
                                </td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 型号：</td>
                                <td style="padding-top:0.3vh;" colspan=5><input id="Model" class="font-rfs" style="margin-top: 0.4rem;width:100%;color:#5d6b98;border:solid 1px;border-color:gainsboro !important;" /></td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0;" colspan=2></td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 实验室：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <select id="Site" class="form-control font-rfs border-radius-noradius custom-td-select" style="color:#5d6b98;width:100% !important;"></select>
                                </td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 工作组：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <select id="Group" class="form-control font-rfs border-radius-noradius custom-td-select" style="color:#5d6b98;width:100% !important;"></select>
                                </td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0;" colspan=2></td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 供应商：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <select id="Supplier" class="form-control font-rfs border-radius-noradius custom-td-select" style="color:#5d6b98;width:100% !important;"></select>
                                </td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 制造商：</td>
                                <td style="padding-top:0.3vh;" colspan=5><input id="Manufacturer" class="font-rfs" style="margin-top: 0.4rem;width:100%;color:#5d6b98;border:none;border:solid 1px;border-color:gainsboro !important;" /></td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0;" colspan=2></td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 购入日期：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <input id="PurchaseDate" class="dtp font-rfs" style="margin-top: 0.4rem;width:100%;color:#5d6b98;border:none;border:solid 1px;border-color:gainsboro !important;" />
                                </td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 启用日期：</td>
                                <td style="padding-top:0.3vh;" colspan=5><input id="EnablingDate" class="dtp font-rfs" style="margin-top: 0.4rem;width:100%;color:#5d6b98;border:none;border:solid 1px;border-color:gainsboro !important;" /></td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0;" colspan=2></td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 安装位置：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <select id="InstallationLocation" class="form-control font-rfs border-radius-noradius custom-td-select" style="color:#5d6b98;width:100% !important;"></select>
                                </td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 出厂编号：</td>
                                <td style="padding-top:0.3vh;" colspan=5><input id="FactoryNumber" class="font-rfs" style="margin-top: 0.4rem;width:100%;color:#5d6b98;border:none;border:solid 1px;border-color:gainsboro !important;" /></td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            <tr style="height:2vh;">
                                <td style="border-top:0;" colspan=2></td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"> 负责人：</td>
                                <td style="padding-top:0.3vh;" colspan=5>
                                    <select id="ResponsiblePerson" class="form-control font-rfs border-radius-noradius custom-td-select" style="color:#5d6b98;width:100% !important;"></select>
                                </td>
                                <td class="font-rfs" style="color:gray;display:table-cell; vertical-align:middle;"></td>
                                <td style="padding-top:0.3vh;" colspan=5>@* <input id="EnablingDate" class="font-rfs" style="margin-top: 0.4rem;width:100%;color:#5d6b98;border:none" /> *@</td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            @*空行*@
                            <tr style="height:33vh">
                                <td style="border-top:0;" colspan=2></td>
                                <td colspan=12></td>
                                <td style="border-top:0;" colspan=2></td>
                            </tr>
                            @*foot*@
                            <tr style="height:1vh;">
                                <td style="border-top:0" colspan=6></td>
                                <td style="background:url(/StaticFile/foot_left.png) no-repeat;background-size:cover;border-top:1px"></td>
                                <td style="background-color:#5d6b98;border-top:0" colspan=3></td>
                                <td style="background:url(/StaticFile/foot_right.png) no-repeat;background-size:cover;border-top:1px"></td>
                                <td style="border-top:0" colspan=5></td>
                            </tr>
                            <tr style="height:1vh;">
                                <td style="border-top:0;"></td>
                                <td style="background-color:#5d6b98;border-top:0" colspan=14></td>
                                <td style="border-top:0"></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane" id="tabMaintain" style="padding-left: 0px;padding-right: 0px;">@*设备维护*@
                <div class="row col-md-12" style="height:1vh"></div>
                <ul class="nav col-md-12" style="margin-bottom: 1px;padding-right: 0px;">
                    <li class="tabButton col-md-1 tab-other-active font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;height:3vh;" data-active="false">
                        <a href="#tabMaintain" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">维护事件</a>
                    </li>
                    <li class="col-md-11 tab-Notactive" style="text-align: center;height:3vh;"><a href="" data-toggle="tab"></a></li>
                </ul>
                <div class="row col-md-12" style="min-height:5vh;">
                        <button id="addMaintainEvent" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                        <button id="EqManager-EnableME" class="btn btn-rfs"><i class="bi-sign-stop-fill" style="color:forestgreen"></i> 启用/停用</button>
                        <button id="deleteMaintainEvent" class="btn btn-rfs"><i class="bi-trash"></i> 删除</button>
                        <button id="EqManager-DoMaintain" class="btn btn-rfs"><i class="bi-wrench-adjustable" style="color:forestgreen"></i> 维护</button>
                </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:24vh;padding-right: 0px;margin-left: 0px;border-bottom: 1px solid #a8bfde;margin-bottom: 5px;">
                    <table id="MaintainEvent" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>描述</th>
                                <th>上次维护</th>
                                <th>频率</th>
                                <th>频率单位</th>
                                <th>下次维护</th>
                                <th>提醒</th>
                                <th>接收组</th>
                                <th>接收人</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <ul class="nav col-md-12" style="margin-bottom: 1px;padding-right: 0px;">
                    <li class="tabButton col-md-1 tab-other-active font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;height:3vh;" data-active="false">
                        <a href="#tabMaintain" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">维护记录</a>
                    </li>
                    <li class="col-md-11 tab-Notactive" style="text-align: center;height:3vh;"><a href="" data-toggle="tab"></a></li>
                </ul>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:47vh;">
                    <table id="Maintain" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>说明</th>
                                <th>开始时间</th>
                                <th>结束时间</th>
                                <th>登记时间</th>
                                <th>维护人</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane" id="tabRole" style="padding-left: 0px;padding-right: 0px;">@*设备备件*@
                <div class="row col-md-12" style="min-height:5vh;">
                    <button id="delRelatedMaterials" class="btn btn-rfs"><i class="bi-link" style="color:red"></i> 删除关联</button>
                </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:81vh">
                    <table id="tabRelatedMaterials" class="table table-striped table-bordered-modal table-sm table-hover">
                        <thead>
                            <tr>
                                <th>物料代码</th>
                                <th>物料名称</th>
                                <th>入库时间</th>
                                <th>剩余数量</th>
                                <th>数量单位</th>
                                <th>存储位置</th>
                                <th>备注</th>
                            </tr>
                        </thead>
                        <tbody style="font-size: calc(0.6em + 0.1vw) !important"></tbody>
                    </table>
                </div>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane" id="tabUseRecord" style="padding-left: 0px;padding-right: 0px;">
                <div class="row col-md-12" style="min-height:5vh;">
                    <button id="addUsageRecord" class="btn btn-rfs"><i class="bi-plus-square" style="color:#007bff"></i> 添加</button>
                </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:81vh">
                    <table id="tabUsageRecord" class="table table-striped table-bordered-modal table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>开始时间</th>
                                <th>结束时间</th>
                                <th>记录时间</th>
                                <th>时长(小时)</th>
                                <th>使用人</th>
                                <th>备注</th>
                                <th>文件</th>
                            </tr>
                        </thead>
                    <tbody style="font-size: calc(0.6em + 0.1vw) !important"></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-Modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p id="EqManager-Modal-Title" class="pt-3 pl-3 font-rfs"></p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div id="EqManager-Modal-AddEq" style="display:none">
                    <div class="input-group">
                        <div class="col-3 pr-0">
                            <span class="input-group-text font-rfs border-radius-noright noRightBorder">实验室和组*</span>
                        </div>
                        <div class="col-9 pl-0 input-group">
                            <select id="Modal-AddEq-Site" class="form-control font-rfs border-radius-noleft" style="width:50%"></select>
                            <select id="Modal-AddEq-Group" class="form-control font-rfs border-radius-noleft" style="width:50%"></select>
                        </div>
                    </div>
                    <div class="input-group">
                        <div class="col-3 pr-0">
                            <span class="input-group-text font-rfs border-radius-noright noRightBorder">设备编号*</span>
                        </div>
                        <div class="col-9 pl-0">
                            <input id="Modal-AddEq-EqId" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
                        </div>
                    </div>
                    <div class="input-group">
                        <div class="col-3 pr-0">
                            <span class="input-group-text font-rfs border-radius-noright noRightBorder">类型*</span>
                        </div>
                        <div class="col-9 pl-0 input-group position-relative">
                            <select id="Modal-AddEq-SelectType" class="form-control font-rfs border-radius-noleft"></select>
                            <div class="col-11 pl-0 input-group position-absolute float-left"><input id="Modal-AddEq-InputType" class="form-control font-rfs border-radius-noleft noRightBorder" style="width:100%" placeholder="可输入新的类型" /></div>
                        </div>
                    </div>
                    <div class="input-group">
                        <div class="col-3 pr-0">
                            <span class="input-group-text font-rfs border-radius-noright noRightBorder">名称*</span>
                        </div>
                        <div class="col-9 pl-0">
                            <input id="Modal-AddEq-Name" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
                        </div>
                    </div>
                    <div class="text-right">
                        <button id="Modal-AddEq-confirm" class="btn btn-primary font-rfs">确定</button>
                        <button id="Modal-AddEq-cancel" data-dismiss="modal" type="button" class="btn btn-info font-rfs">取消</button>
                    </div>
                </div>
                <div id="Embed" style="display:none"></div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-RemoveEq-Modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除设备</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">设备删除后将不可恢复，是否继续？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="RemoveEq-Modal-confirm" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">确定</button>
                <button id="RemoveEq-Modal--cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-ScrapEq-Modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">报废设备</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">设备报废后将不能再启用，是否继续？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="ScrapEq-Modal-confirm" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">确定</button>
                <button id="ScrapEq-Modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-AddMaintainEvent" role="dialog">@*添加维护事件*@
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">添加维护事件</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">名称*</span>
                    </div>
                    <div class="col-9 pl-0 input-group position-relative">
                        <input id="AddMaintainEvent-Name" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
                    </div>
                </div>
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">描述</span>
                    </div>
                    <div class="col-9 pl-0">
                        <input id="AddMaintainEvent-Description" class="form-control font-rfs border-radius-noleft"/>
                    </div>
                </div>
                <div class="text-right">
                    <button id="AddMaintainEvent-confirm" class="btn btn-primary font-rfs">确定</button>
                    <button id="AddMaintainEvent-cancel" data-dismiss="modal" type="button" class="btn btn-info font-rfs">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-RemoveME-Modal" role="dialog">@*删除维护事件*@
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除设备维护事件</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">删除设备维护事件时，该事件关联的维护记录将一并删除。此操作不可恢复，是否继续删除？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="RemoveME-Modal-confirm" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">确定</button>
                <button id="RemoveME-Modal--cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-DoMaintainEvent" role="dialog">
    @*执行维护操作*@
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">执行维护</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">开始时间*</span>
                    </div>
                    <div class="col-9 pl-0 input-group position-relative">
                        <input id="DoMaintainEvent-StarTime" type="text" class="form-control font-rfs border-radius-noleft" />
                    </div>
                </div>
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">结束时间*</span>
                    </div>
                    <div class="col-9 pl-0 input-group position-relative">
                        <input id="DoMaintainEvent-EndTime" type="text" class="form-control font-rfs border-radius-noleft" />
                    </div>
                </div>
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">维护说明</span>
                    </div>
                    <div class="col-9 pl-0">
                        <textarea id="DoMaintainEvent-Description" rows="3" class="form-control font-rfs border-radius-noleft"></textarea>
                    </div>
                </div>
                <div class="text-right">
                    <button id="DoMaintainEvent-confirm" class="btn btn-primary font-rfs">确定</button>
                    <button id="DoMaintainEvent-cancel" data-dismiss="modal" type="button" class="btn btn-info font-rfs">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-DelRelatedMaterials" role="dialog">
    @*删除所选物料与设备的关联*@
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除关联</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">删除所选物料与设备的关联？若要恢复关联，转到物料管理页面进行设置。</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="EqManager-DelRelatedMaterials-confirm" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="EqManager-DelRelatedMaterials-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="EqManager-CommonModal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p id="EqManager-CommonModal-Title" class="pt-3 pl-3 font-rfs"></p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div id="EqManager-CommonModal-Embed"></div>
            </div>
        </div>
    </div>
</div>


@section Scripts{
    <script>
        var EqManager_EqId = "";
        var EqManager_EventId = "";
        var GroupList;

        $(document).ready(function () {
            LoadEqList();
            LoadEquipmentTypeList('EqManager-SelectType');
            LoadEquipmentTypeList('Type');
            LoadSiteList('Site');
            LoadSupplierList('Supplier', '仪器设备');
            GetLocationList('InstallationLocation', '仪器设备');
            LoadUsers('ResponsiblePerson');
            ClearControl();
            GetGroupList();

            $('.dtp').datetimepicker({
                timepicker: true,
                format: "Y/m/d H:i",
                setLocale: 'zh'
            });
        });

        function ClearControl() {  // F5刷新时清空控件
            $("#EqId").val('');
            $("#EqName").val('');
            $("#Type").val('');
            $("#Model").val('');
            $("#Site").val('');
            $("#Group").val('');
            $("#Supplier").val('');
            $("#Manufacturer").val('');
            $('#InstallationLocation').val('');
            $('#FactoryNumber').val('');
            $('#ResponsiblePerson').val('');
            $('#PurchaseDate').val('');
            $('#EnablingDate').val('');
        }

        function GetGroupList() {
            $.post("/Sample/GetWorkGroupList", {
                //Site: SiteName
            }, function (data) {
                GroupList = data;
            });
        }

        function LoadEqList() {
            var columns = [{ field: "id" }, { field: "name" }, { field: "status", width: "5%", align: "center", formatter: SetStatus }];
            var eqType = $('#EqManager-SelectType').find("option:selected").text();

            $('#EqManager-tabEq').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#EqManager-tabEq').bootstrapTable({
                method: 'post',
                url: "GetEqList",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                silent: true,  //刷新事件必须设置
                queryParams: function (params) {
                    var data = {
                        EqType: eqType,
                        limit: params.limit, // 每页显示多少条记录
                        offset: params.offset, // 偏移量
                    };
                    return data;
                },

                queryParamsType: "limit", 
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 20,   // 默认页大小
                pageList: [10, 20, 30, 50, 100],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,

                onClickRow: function (row, $element, field) {
                    $("#EqManager-tabEq").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    EqManager_EqId = row.id;
                    LoadEqInfo(EqManager_EqId);
                    LoadMaintainEvent(EqManager_EqId);
                    LoadRelatedMaterials(EqManager_EqId);
                    LoadUsageRecord(EqManager_EqId);
                    $('#Maintain').bootstrapTable('destroy');
                },
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#EqManager-tabEq').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#EqManager-SelectType").change(function () {
            LoadEqList();
        });

        function SetStatus(value, row, index) {
            var strHtml = "-";
            if (value == "启用") {
                strHtml = "<i class='bi-sign-stop-fill' style='color:forestgreen'></i>";
            }
            if (value == "停用") {
                strHtml = "<i class='bi-sign-stop-fill' style='color:red'></i>";
            }
            if (value == "报废") {
                strHtml = "<i class='bi-stop-circle' style='color:red'></i>";
            }
            return strHtml;
        }

        $("#EqManager-EnableEq").click(function () {
            if (EqManager_EqId.length == 0) {
                alert("请先选择需要操作的设备！");
                return;
            }

            var row = $('#EqManager-tabEq').bootstrapTable('getRowByUniqueId', EqManager_EqId); // 获得行数据
            if (row.status == "报废") {
                alert("该设备已报废！");
                return;
            }

            $.post("UpdateEquipmentStatus", {
                EqId: EqManager_EqId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    if (row.status == "启用") {
                        row.status = "停用";
                    } else {
                        row.status = "启用";
                    }
                    $('#EqManager-tabEq').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                    EqManager_EqId = "";
                }            
            });
        });

        $("#EqManager-ScrapEq").click(function () {
            if (EqManager_EqId.length == 0) {
                alert("请先选择需要操作的设备！");
                return;
            }

            var row = $('#EqManager-tabEq').bootstrapTable('getRowByUniqueId', EqManager_EqId); // 获得行数据
            if (row.status == "报废") {
                alert("该设备已报废！");
                return;
            }

            $("#EqManager-ScrapEq-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#ScrapEq-Modal-confirm").click(function () {
            $.post("UpdateEquipmentScrap", {
                EqId: EqManager_EqId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    var row = $('#EqManager-tabEq').bootstrapTable('getRowByUniqueId', EqManager_EqId); // 获得行数据
                    row.status = "报废";
                    $('#EqManager-tabEq').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                    EqManager_EqId = "";
                    $("#EqManager-ScrapEq-Modal").modal('hide');
                } else {
                    alert(data);
                }
            });
        });

        $("#EqManager-RemoveEq").click(function () {
            if (EqManager_EqId.length == 0) {
                alert("请先选择需要操作的设备！");
                return;
            }

            $("#EqManager-RemoveEq-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#RemoveEq-Modal-confirm").click(function () {
            $.post("RemoveEquipment", {
                EqId: EqManager_EqId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $('#EqManager-tabEq').bootstrapTable('removeByUniqueId', EqManager_EqId);
                    $("#EqManager-RemoveEq-Modal").modal('hide');
                } else {
                    alert(data);
                }
            });
        });

        $("#EqManager-AddEq").click(function () {
            $.post("GetEquipmentTypeList", {
                //Type: type
            }, function (data) {
                $("#Modal-AddEq-SelectType").empty();
                for (var i = 0; i < data.length; i++) {
                    $("#Modal-AddEq-SelectType").append(new Option(data[i]));
                }
                $("#Modal-AddEq-SelectType").prepend(new Option("", ""));
                $("#Modal-AddEq-SelectType").val("");
            });

            LoadSiteList('Modal-AddEq-Site');

            $("#EqManager-Modal-Title").text("添加设备");

            $("#EqManager-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });
            $("#EqManager-Modal-AddEq").css('display', 'block');
            $("#Embed").css('display', 'none');
        });

        //根据选择的实验室加载工作组
        $("#Modal-AddEq-Site").change(function () {
            var site = $("#Modal-AddEq-Site").find("option:selected").text();
            LoadGroupList(site, 'Modal-AddEq-Group');
        });
        $("#Site").change(function () {
            var site = $("#Site").find("option:selected").text();
            LoadGroupList(site, 'Group');
        });

        $("#Modal-AddEq-SelectType").change(function () {
            $("#Modal-AddEq-InputType").val($("#Modal-AddEq-SelectType").find("option:selected").text());
        });

        $("#Modal-AddEq-confirm").click(function () {
            if ($('#Modal-AddEq-EqId').val().length == 0) {
                alert("设备ID不能为空！");
                $("#Modal-AddEq-EqId").addClass('error-style');
                return false;
            }
            if ($('#Modal-AddEq-Name').val().length == 0) {
                alert("设备名称不能为空！");
                $("#Modal-AddEq-Name").addClass('error-style');
                return false;
            }
            if ($.trim($("#Modal-AddEq-InputType").val()).length == 0) {
                alert("设备类型不能为空！");
                $("#Modal-AddEq-InputType").addClass('error-style');
                return false;
            }
            if ($("#Modal-AddEq-Site").find("option:selected").text().length == 0) {
                alert("设备所属实验室不能为空！");
                $("#Modal-AddEq-Site").addClass('error-style');
                return false;
            }
            if ($("#Modal-AddEq-Group").find("option:selected").text().length == 0) {
                alert("设备所属工作组不能为空！");
                $("#Modal-AddEq-Group").addClass('error-style');
                return false;
            }

            $.post("CreatEquipment", {
                EqId: $('#Modal-AddEq-EqId').val(),
                EqName: $('#Modal-AddEq-Name').val(),
                EqType: $.trim($("#Modal-AddEq-InputType").val()),
                Site: $("#Modal-AddEq-Site").find("option:selected").text(),
                Group: $("#Modal-AddEq-Group").find("option:selected").text()
            }, function (data) {
                alert(data);
            });
        });

        function LoadEqInfo(EqId) { // 加载设备详细信息
            $.post("GetEquipmentInfo", {
                EqId: EqId
            }, function (data) {
                if (data.length == 0) {
                    $("#EqId").val('');
                    $("#EqName").val('');
                    $("#Type").val('');
                    $("#Model").val('');
                    $("#Site").val('');
                    LoadGroupList('');
                    $("#Supplier").val('');
                    $("#Manufacturer").val('');
                    $('#InstallationLocation').val('');
                    $('#FactoryNumber').val('');
                    $('#ResponsiblePerson').val('');
                } else {
                    $("#EqId").val(data[0].id);
                    $("#EqName").val(data[0].name);
                    $("#Type").val(data[0].type);
                    $("#Model").val(data[0].model);
                    $("#Site").val(data[0].site);
                    LoadGroupList(data[0].site, 'Group', data[0].group);
                    $("#Supplier").val(data[0].supplierId);
                    $("#Manufacturer").val(data[0].manufacturer);
                    $('#PurchaseDate').val(data[0].purchaseDate.replace('T', ' '));
                    $('#EnablingDate').val(data[0].enablingDate.replace('T', ' '));
                    $('#InstallationLocation').val(data[0].installationLocation);
                    $('#FactoryNumber').val(data[0].factoryNumber);
                    $('#ResponsiblePerson').val(data[0].responsiblePersonId);
                }
            });
        }

        $("#EqManager-SaveEqInfo").click(function () {
            var eqId = EqManager_EqId;
            if (eqId.length == 0) {
                return;
            }

            var eqStr = {};
            eqStr["Id"] = eqId;
            eqStr["Name"] = $("#EqName").val();
            eqStr["Type"] = $('#Type').find("option:selected").text();
            eqStr["Model"] = $("#Model").val();
            eqStr["Manufacturer"] = $("#Manufacturer").val();
            eqStr["Site"] = $('#Site').find("option:selected").text();
            eqStr["Group"] = $('#Group').find("option:selected").text();
            eqStr["SupplierId"] = $('#Supplier').find("option:selected").val();
            eqStr["PurchaseDate"] = $('#PurchaseDate').val();
            eqStr["EnablingDate"] = $('#EnablingDate').val();
            eqStr["InstallationLocation"] = $('#InstallationLocation').find("option:selected").text();
            eqStr["FactoryNumber"] = $('#FactoryNumber').val();
            eqStr["ResponsiblePersonId"] = $('#ResponsiblePerson').find("option:selected").val();
            eqStr["ResponsiblePerson"] = $('#ResponsiblePerson').find("option:selected").text();

            var infoStr = {}; // 扩展信息 
            infoStr["EquipmentId"] = eqId;

            $.post("UpdateEquipmentInfo", {
                eqStr: JSON.stringify(eqStr),
                infoStr: JSON.stringify(infoStr)
            }, function (data) {
                alert(data);
            });
        });

        $("#EqManager-ManagerFiles").click(function () {
            var eqId = $("#EqId").val();
            if (eqId.length == 0) {
                return;
            }

            $("#EqManager-Modal-Title").text("设备附件管理");
            $("#EqManager-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $("#EqManager-Modal-AddEq").css('display', 'none');
            $("#Embed").css('display', 'block');

            $.post("/Common/ManageFile", {
                Domain: "Equipment",
                DomainId: eqId,
                ModalID: "EqManager-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#addMaintainEvent").click(function () {
            var eqId = $("#EqId").val();
            if (eqId.length == 0) {
                alert("请先选择设备！");
                return;
            }

            $("#EqManager-AddMaintainEvent").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#AddMaintainEvent-confirm").click(function () {
            $.post("CreatMaintainEvent", {
                EqId: $("#EqId").val(),
                EventsName:$("#AddMaintainEvent-Name").val(),
                Description:$('#AddMaintainEvent-Description').val()
            }, function (data) {
                LoadMaintainEvent($("#EqId").val());
                $("#EqManager-AddMaintainEvent").modal('hide');
            });
        });

        function setFrequency(value, row, index) {
            var strHtml = "<input class='table-cell-input' onchange='UpdateFrequency(this)' value='" + value + "'/>";
            return strHtml;
        }
        
        function setRemind(value, row, index) {
            var strHtml = "<input class='table-cell-input' onchange='UpdateRemind(this)' value='" + value + "'/>";
            return strHtml;
        }

        function setFrequencyUnit(value, row, index) {
            var strHtml = "";
            if (value == null) {
                strHtml = "<select class='table-cell-input' onchange='UpdateFrequencyUnit(this)' ><option></option><option>天</option><option>周</option><option>月</option><option>年</option></select>";
            }
            if (value == '天') {
                strHtml = "<select class='table-cell-input' onchange='UpdateFrequencyUnit(this)' ><option selected >天</option><option>周</option><option>月</option><option>年</option></select>";
            }
            if (value == '周') {
                strHtml = "<select class='table-cell-input' onchange='UpdateFrequencyUnit(this)' ><option>天</option><option selected >周</option><option>月</option><option>年</option></select>";
            }
            if (value == '月') {
                strHtml = "<select class='table-cell-input' onchange='UpdateFrequencyUnit(this)' ><option>天</option><option>周</option><option selected >月</option><option>年</option></select>";
            }
            if (value == '年') {
                strHtml = "<select class='table-cell-input' onchange='UpdateFrequencyUnit(this)' ><option>天</option><option>周</option><option>月</option><option selected >年</option></select>";
            }

            return strHtml;
        }

        function setGroup(value, row, index) {
            var str = "<option></option>";
            for (var i = 0; i < GroupList.length; i++) {
                if (value == GroupList[i].workGroup) {
                    str = str + "<option selected value='" + GroupList[i].id + "'>" + GroupList[i].workGroup + "</option>";
                } else {
                    str = str + "<option value='" + GroupList[i].id + "'>" + GroupList[i].workGroup + "</option>";
                }
            }
            var strHtml = "<select class='table-cell-input' onchange='UpdateGroup(this)' >" + str + "</select>";
            return strHtml;
        }

        function UpdateFrequency(obj) {
            var frequency = $(obj).val();
	        var id = $(obj).parent().parent().attr('data-uniqueid');  // 获得单元格所在行的 ID
            var row = $('#MaintainEvent').bootstrapTable('getRowByUniqueId', EqManager_EventId); // 获得行数据

            var reg = /^[1-9]\d*$/;
            if (!reg.test(frequency)) {
                alert("频率只能为正整数！");
                return;
            }

            $.post("UpdateMaintainEventFrequency", {
                Id: id,
                Frequency: frequency
            },  function (data) {
                if (data.indexOf("成功") >= 0) {
                    $.post("GetMaintainEvent", {
                        Id: id
                    },  function (data) {
                        row.frequency = data.frequency
                        row.nextTime = data.nextTime;
                        $('#MaintainEvent').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                    });
                } else {
                    alert(data);
                }
            });
        }

        function UpdateFrequencyUnit(obj) {
            var unit = $(obj).find("option:selected").text();
	        var id = $(obj).parent().parent().attr('data-uniqueid');  // 获得单元格所在行的 ID
            var row = $('#MaintainEvent').bootstrapTable('getRowByUniqueId', EqManager_EventId); // 获得行数据

            $.post("UpdateMaintainEventFrequencyUnit", {
                Id: id,
                FrequencyUnit: unit
            },  function (data) {
                if (data.indexOf("成功") >= 0) {
                    $.post("GetMaintainEvent", {
                        Id: id
                    },  function (data) {
                        row.frequencyUnit = data.frequencyUnit;
                        row.nextTime = data.nextTime;
                        $('#MaintainEvent').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                    });
                } else {
                    alert(data);
                }
            });
        }

        function UpdateGroup(obj) {
            var sendToGroup = $(obj).find("option:selected").text();
            var sendToGroupId = $(obj).find("option:selected").val();
            var id = $(obj).parent().parent().attr('data-uniqueid');  // 获得单元格所在行的 ID

            $.post("UpdateMaintainEventGroup", {
                Id: id,
                SendToGroup: sendToGroup,
                SendToGroupId: sendToGroupId
            }, function (data) {
                alert(data);
            });
        }

        function UpdateRemind(obj) {
            var remind = $(obj).val();
            var id = $(obj).parent().parent().attr('data-uniqueid');  // 获得单元格所在行的 ID

            var reg = /^[1-9]\d*$/;
            if (!reg.test(remind)) {
                alert("提醒天数只能为正整数！");
                return;
            }

            $.post("UpdateMaintainEventRemind", {
                Id: id,
                Remind: remind
            }, function (data) {
                alert(data);
            });
        }

        function LoadMaintainEvent(EqId) {
            var columns = [{ field: "id", visible: false }, { field: "eventsName" }, { field: "description" }, { field: "lastTime", formatter: setTime },
            { field: "frequency", formatter: setFrequency }, { field: "frequencyUnit", formatter: setFrequencyUnit }, { field: "nextTime", formatter: setTime },
            { field: "remind", formatter: setRemind }, { field: "sendToGroup", formatter: setGroup }, { field: "sendToPerson" },
            { field: "status", width: "5%", align: "center", formatter: SetStatus }];

            $('#MaintainEvent').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#MaintainEvent').bootstrapTable({
                method: 'post',
                url: "GetMaintainEventList",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                silent: true,  //刷新事件必须设置
                queryParams: function (params) {
                    var data = {
                        EqId: EqId,
                    };
                    return data;
                },

                queryParamsType: "search",
                pagination: false,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 10,   // 默认页大小
                pageList: [10, 20, 30, 50, 100],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,

                onClickRow: function (row, $element, field) {
                    $("#MaintainEvent").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    EqManager_EventId = row.id;
                    if (field == 'eventsName' || field == 'description') {
                        LoadMaintain(EqManager_EventId);
                    }
                },
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#MaintainEvent').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();

                    $('.TimePicker').datetimepicker({
                        timepicker: false,
                        format: "Y/m/d H:i"
                    });
                    $.datetimepicker.setLocale('zh'); 
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function LoadRelatedMaterials(EqId) {
            var columns = [{ field: "materialCode" }, { field: "materialName" }, { field: "inDate", formatter: setTime },
            { field: "receivedQuantity" }, { field: "availableUnit" }, { field: "positionId" }, { field: "note" }];

            $('#tabRelatedMaterials').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#tabRelatedMaterials').bootstrapTable({
                method: 'post',
                url: "GetRelatedMaterials",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                uniqueId: "materialCode",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                silent: true,  //刷新事件必须设置
                queryParams: function (params) {
                    var data = {
                        EqId: EqId,
                    };
                    return data;
                },

                queryParamsType: "search",
                pagination: false,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 10,   // 默认页大小
                pageList: [10, 20, 30, 50, 100],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,

                onClickRow: function (row, $element, field) {
                    $("#tabRelatedMaterials").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#tabRelatedMaterials').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#EqManager-EnableME").click(function () {
            if (EqManager_EventId.length == 0) {
                alert("请先选择设备维护事件！");
                return;
            }

            var row = $('#MaintainEvent').bootstrapTable('getRowByUniqueId', EqManager_EventId); // 获得行数据
            $.post("UpdateMaintainEventStatus", {
                Id: EqManager_EventId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    if (row.status == "启用") {
                        row.status = "停用";
                    } else {
                        row.status = "启用";
                    }
                    $('#MaintainEvent').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                    EqManager_EventId = "";
                }            
            });
        });

        $("#deleteMaintainEvent").click(function () {
            if (EqManager_EventId.length == 0) {
                alert("请先选择设备维护事件！");
                return;
            }

            $("#EqManager-RemoveME-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#RemoveME-Modal-confirm").click(function () {
            $.post("RemoveMaintainEvent", {
                Id: EqManager_EventId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    LoadMaintainEvent($("#EqId").val());
                    $("#EqManager-RemoveME-Modal").modal('hide');
                } else {
                    alert(data);
                }
            });
        });

        $("#EqManager-DoMaintain").click(function () {
            if (EqManager_EventId.length == 0) {
                alert("请先选择设备维护事件！");
                return;
            }

            $('#DoMaintainEvent-StarTime').datetimepicker({
                timepicker: true,
                format: "Y/m/d H:i"
            });
            $('#DoMaintainEvent-EndTime').datetimepicker({
                timepicker: true,
                format: "Y/m/d H:i"
            });
            $.datetimepicker.setLocale('zh');

            $("#EqManager-DoMaintainEvent").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#delRelatedMaterials").click(function () {
            if (GetSelectIdByColor('tabRelatedMaterials').length == 0) {
                alert("请先选择设备备件！");
                return;
            }

            $("#EqManager-DelRelatedMaterials").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#DoMaintainEvent-confirm").click(function () {
            var jsonStr = {};
            jsonStr["MaintainEventId"] = EqManager_EventId;
            jsonStr["EqId"] = EqManager_EqId;
            jsonStr["StarTime"] = $('#DoMaintainEvent-StarTime').val();
            jsonStr["EndTime"] = $('#DoMaintainEvent-EndTime').val();
            jsonStr["Description"] = $('#DoMaintainEvent-Description').val();

            $.post("DoMaintainEvent", {
                jsonStr: JSON.stringify(jsonStr)
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    LoadMaintain(EqManager_EventId);
                    var row = $('#MaintainEvent').bootstrapTable('getRowByUniqueId', EqManager_EventId); // 获得行数据

                    $.post("GetMaintainEvent", {
                        Id: EqManager_EventId
                    }, function (data) {
                        row.lastTime = data.lastTime;
                        row.nextTime = data.nextTime;
                        $('#MaintainEvent').bootstrapTable('updateByUniqueId', row);
                    });

                    $("#EqManager-DoMaintainEvent").modal('hide');
                } else {
                    alert(data);
                    if (data.indexOf("开始") >= 0) {
                        $("#DoMaintainEvent-StarTime").addClass('error-style');
                    }
                    if (data.indexOf("结束") >= 0) {
                        $("#DoMaintainEvent-EndTime").addClass('error-style');
                    }
                }
            });
        });

        $("#EqManager-DelRelatedMaterials-confirm").click(function () {
            var id = GetSelectIdByColor('tabRelatedMaterials');
            $.post("DelRelatedMaterialAndEq", {
                Code: id
            }, function (data) {
                LoadRelatedMaterials(EqManager_EqId);
                alert(data);
                $("#EqManager-DelRelatedMaterials").modal('hide');
            });
        });

        function setTime(value, row, index) {
            if (value != null)
                return value.replace('T', ' ');
        }

        function LoadMaintain(MaintainEventId) {
            var columns = [{ field: "id", visible: false }, { field: "description" }, { field: "starTime", formatter: setTime },
            { field: "endTime", formatter: setTime }, { field: "recordTime", formatter: setTime }, { field: "personName" }];

            $('#Maintain').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#Maintain').bootstrapTable({
                method: 'post',
                url: "GetMaintainList",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                silent: true,  //刷新事件必须设置
                queryParams: function (params) {
                    var data = {
                        EventId: MaintainEventId,
                        limit:params.limit, // 每页显示多少条记录
                        offset:params.offset // 偏移量
                    };
                    return data;
                },

                queryParamsType: "limit",
                dataField: "rows",
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 15,   // 默认页大小
                pageList: [10, 20, 30, 50, 100],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,

                onClickRow: function (row, $element, field) {
                    $("#Maintain").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Maintain').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function SetMethodButton(value, row, index) {
            if (value != null)
                return strHtml = "<button class='table-cell-button btn-rfs' value='" + value + "'  title='查看数据文件内容' onclick='DowloadFile(this)'><i class='bi-file-text'></i></button>";
            return '-';
        }

        function DowloadFile(obj) {
            DownloadFile($(obj).val());
        }

        function LoadUsageRecord(EqId) {
            var columns = [{ field: "id", visible: false }, { field: "startTime", formatter: setTime }, { field: "endTime", formatter: setTime },
            { field: "recordTime", formatter: setTime }, { field: "duration" }, { field: "personName" }, { field: "note" },
            { field: "fileID", width: "5%", formatter: SetMethodButton }];

            $('#tabUsageRecord').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#tabUsageRecord').bootstrapTable({
                method: 'post',
                url: "GetUsageRecords",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                silent: true,  //刷新事件必须设置
                queryParams: function (params) {
                    var data = {
                        EqId: EqId,
                        limit: params.limit, // 每页显示多少条记录
                        offset: params.offset, // 偏移量
                    };
                    return data;
                },

                queryParamsType: "limit",
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 20,   // 默认页大小
                pageList: [10, 20, 30, 50, 100],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,

                onClickRow: function (row, $element, field) {
                    $("#tabUsageRecord").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#tabUsageRecord').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#addUsageRecord").click(function () {
            if (EqManager_EqId.length == 0) {
                alert("请先选择设备！");
                return;
            }

            $("#EqManager-CommonModal-Title").text("添加设备使用记录");

            $("#EqManager-CommonModal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("/Common/AddUsageRecord", {
                ModalID: "EqManager-CommonModal",
                EqId: EqManager_EqId
            }, function (datas) {
                $("#EqManager-CommonModal-Embed").html(datas);
            });
        });

//********************************************************************************

        $(".tab").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-other-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-other-noactive') > 0) {
                    $(this).removeClass('tab-other-noactive');
                    $(this).addClass('tab-other-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-other-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-other-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-other-noactive');
                }
            });

        $("#a-tabEqInfo").click(function () {
            if ($("#li-tabMaintain").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabMaintain").removeClass('tab-other-active');
                $("#li-tabMaintain").addClass('tab-other-noactive');
            }

            if ($("#li-tabRole").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabRole").removeClass('tab-other-active');
                $("#li-tabRole").addClass('tab-other-noactive');
            }

            $("#li-tabEqBaseInfo").attr("data-active", true);
            $("#li-tabMaintain").attr("data-active", false);
            $("#li-tabRole").attr("data-active", false);
        });

        $("#a-tabMaintain").click(function () {
            if ($("#li-tabEqBaseInfo").attr("class").indexOf('tab-first-active') > 0) {
                $("#li-tabEqBaseInfo").removeClass('tab-first-active');
                $("#li-tabEqBaseInfo").addClass('tab-first-noactive');
            }

            if ($("#li-tabRole").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabRole").removeClass('tab-other-active');
                $("#li-tabRole").addClass('tab-other-noactive');
            }

            $("#li-tabMaintain").attr("data-active", true);
            $("#li-tabEqBaseInfo").attr("data-active", false);
            $("#li-tabRole").attr("data-active", false);
        });

        $("#a-tabRole").click(function () {
            if ($("#li-tabEqBaseInfo").attr("class").indexOf('tab-first-active') > 0) {
                $("#li-tabEqBaseInfo").removeClass('tab-first-active');
                $("#li-tabEqBaseInfo").addClass('tab-first-noactive');
            }
            if ($("#li-tabMaintain").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabMaintain").removeClass('tab-other-active');
                $("#li-tabMaintain").addClass('tab-other-noactive');
            }

            $("#li-tabRole").attr("data-active", true);
            $("#li-tabEqBaseInfo").attr("data-active", false);
            $("#li-tabMaintain").attr("data-active", false);
        });

    </script>
}
